	<?php 
	defined('G_IN_SYSTEM')or exit('No permission resources.');
	System::load_app_class('base','member','no');
	System::load_app_fun('my','go');
	System::load_app_fun('user','go');
	System::load_sys_fun('send');
	System::load_sys_fun('user');
	class home extends base {
		public function __construct(){ 
			parent::__construct();
			if(ROUTE_A!='userphotoup' and ROUTE_A!='singphotoup'){


			}	
			$this->db = System::load_sys_class('model');

		}
		
		//用户晒单详情 
		public function usershaidandetail(){
			$webtitle="晒单详情";
			$shaidanid=$this->segment(4);
			$shopid=$this->segment(5);
			$member=$this->userinfo;
			$shaidan = $this->db->GetOne("select * from `@#_shaidan` where `sd_id`='$shaidanid'");
			$shopinfo = $this->db->GetOne("select * from `@#_shoplist` where `id`='$shopid'");

			include templates("mobile/user","shaidandetail");

		}

		public function init(){
			$webname=$this->_cfg['web_name'];
			$title="我的会员中心";	
			$member=$this->userinfo;
			if(!$member){
				include templates("mobile/user","NoLoginIndex");
			}else{
		 //获取云购等级  云购新手  云购小将==
				$memberdj=$this->db->GetList("select * from `@#_member_group`");	   
				$jingyan=$member['jingyan'];
				if(!empty($memberdj)){
					foreach($memberdj as $key=>$val){
						if($jingyan>=$val['jingyan_start'] && $jingyan<=$val['jingyan_end']){
							$member['yungoudj']=$val['name'];
						}
					}
				}  
				include templates("mobile/user","index");
			}
		}
		function invite(){
			$webname=$this->_cfg['web_name'];
			$member=$this->userinfo;
			$title="我的会员中心";
	//$quanzi=$this->db->GetList("select * from `@#_quanzi_tiezi` order by id DESC LIMIT 5");
	//获取云购等级  云购新手  云购小将==
			$memberdj=$this->db->GetList("select * from `@#_member_group`");
			$jingyan=$member['jingyan'];
			if(!empty($memberdj)){
				foreach($memberdj as $key=>$val){
					if($jingyan>=$val['jingyan_start'] && $jingyan<=$val['jingyan_end']){
						$member['yungoudj']=$val['name'];
					}
				}
			}
			include templates("mobile/user","invite");
		}




	//云购记录
	public function userbuylist(){
		$webname=$this->_cfg['web_name'];
		$mysql_model=System::load_sys_class('model');
		$member=$this->userinfo;
		$uid = $member['uid'];
		$webtitle="订单记录";					
		/*$shoplistall=$this->db->GetList("select *,sum(gonumber) as gonumber from `@#_member_go_record` a left join `@#_shoplist` b on a.shopid=b.id where a.uid='$member[uid]' GROUP BY shopid ");*/
		$startshoplist=$this->db->GetList("select *,sum(gonumber) as gonumber from `@#_member_go_record` a left join `@#_shoplist` b on a.shopid=b.id where a.uid='$member[uid]'and b.q_user_code is NULL and b.shenyurenshu >'0' and b.q_end_time is null GROUP BY shopid  " );	
		$endshoplist=$this->db->GetList("select *,sum(gonumber) as gonumber from `@#_member_go_record` a left join `@#_shoplist` b on a.shopid=b.id where a.uid='$member[uid]' and b.q_end_time is not null GROUP BY shopid " );		
		include templates("mobile/user","userbuylist");
	}
	//购买记录详细
	public function userbuydetail(){
		$webname=$this->_cfg['web_name'];
		$mysql_model=System::load_sys_class('model');
		$member=$this->userinfo;
		$webtitle="购买详情";
		$crodid=intval($this->segment(4));
		$record=$mysql_model->GetOne("select * from `@#_member_go_record` where `id`='$crodid' and `uid`='$member[uid]' LIMIT 1");		
		if($crodid>0){
			include templates("mobile/user","userbuydetail");
		}else{
			echo _messagemobile("页面错误",WEB_PATH."/mobile/home/userbuylist",3);
		}
	}
	//获得的商品
	public function orderlist(){

		$member=$this->userinfo;
		$webtitle="领取奖励";
	//$record=$this->db->GetList("select * from `@#_member_go_record` where `uid`='".$member['uid']."' and `huode`>'10000000' ORDER BY id DESC");	
		$member = $this->userinfo;
		$uid = $member['uid'];
		$address = $this->db->GetOne("select * from `@#_member_dizhi` where uid='$uid' and `default`='y'");
	$orderlist=$this->db->GetList("select * from `@#_member_go_record` a left join `@#_shoplist` b on a.shopid=b.id where b.q_uid='$uid' and a.status='已付款,未发货,未完成' and a.huode!=0 order by a.time desc " );//未发货
	$orderlist1=$this->db->GetList("select * from `@#_member_go_record` a left join `@#_shoplist` b on a.shopid=b.id where b.q_uid='$uid' and a.status='已付款,已发货,待收货' and a.huode!=0 order by a.time desc " );//已发货
	$orderlist2=$this->db->GetList("select * from `@#_member_go_record` a left join `@#_shoplist` b on a.shopid=b.id where b.q_uid='$uid' and a.status='已付款,已发货,已完成' and a.huode!=0 order by a.time desc " );//已完成


	include templates("mobile/user","orderlist");
	}
	//账户管理
	public function userbalance(){
		$webname=$this->_cfg['web_name'];
		$member=$this->userinfo;
		$webtitle="账户明细";
		$uid = $member['uid'];
	$addacount = $this->db->GetList("select * from `@#_member_account` where `uid`='$uid'and `type` = '1' and `money` != '0' and `pay` = '账户' ORDER BY time DESC");//充值明细

	$buyacount = $this->db->GetList("select * from `@#_member_account` where `uid`='$uid' and  `type` = '-1' and `money` != '0' and `pay` = '账户' ORDER BY time DESC");//消费明细

	include templates("mobile/user","userbalance");
	}


	public function userrecharge(){
		$webname=$this->_cfg['web_name'];
		$webtitle = "充值";
		$member=$this->userinfo;
		$title="账户充值";
	//$paylist = $this->db->GetList("SELECT * FROM `@#_pay` where `pay_start` = '1'");

		include templates("mobile/user","recharge");
	}	

	//晒单
	public function singlelist(){
		$webname=$this->_cfg['web_name'];
		$webtitle="我的晒单";
		$member=$this->userinfo;
		$cord=$this->db->Getlist("select a.* from `@#_member_go_record` as a left join`@#_shoplist` as b on a.shopid=b.id where a.`uid`='$member[uid]' and a.`huode` > '10000000' and b.q_showtime='N'");

		$shaidan=$this->db->Getlist("select * from `@#_shaidan` where `sd_userid`='$member[uid]'  order by `sd_id`");

		
		$sd_id = $r_id = array();
		foreach($shaidan as $sd){
			if(!empty($sd['sd_shopid'])){
				$sd_id[]=$sd['sd_shopid'];
			}
		}
		foreach($cord as $rd){
			if(!in_array($rd['shopid'],$sd_id)){
				$r_id[]=$rd['shopid'];
			}
		}

		if(!empty($r_id)){
			$rd_id=implode(",",$r_id);
			$rd_id = trim($rd_id,',');
		}else{
			$rd_id="0";
		}
		
		$record = $this->db->Getlist("select * from `@#_member_go_record` as a left join `@#_shoplist` as b on a.shopid=b.id where a.shopid in ($rd_id) and a.`uid`='$member[uid]' and a.`huode`>'10000000' and b.q_showtime='N'");
		
		$shaidan=$this->db->Getlist("select * from `@#_shaidan` where `sd_userid`='$member[uid]' and `grade` !='D' order by `sd_id`");
		$shaidanCHENK=$this->db->Getlist("select * from `@#_shaidan` where `sd_userid`='$member[uid]' and `grade` ='D' order by `sd_id`");
		include templates("mobile/user","singlelist");
	}	
	//我的积分
	public function usernumerical()
	{
		include templates("mobile/user","numerical");
	}
	//揭晓提醒
	public function userreminded()
	{
		include templates("mobile/user","reminded");
	}
	//收货地址
	public function address()
	{
		$member=$this->userinfo;
		$title="收货地址";
		$member_dizhi=$this->db->Getlist("select * from `@#_member_dizhi` where uid='".$member['uid']."' limit 5");
		foreach($member_dizhi as $k=>$v){		
			$member_dizhi[$k] = _htmtocode($v);
		}
		$count=count($member_dizhi);

		include templates("mobile/user","address");
	}



	}

	?>